import request from '@/utils/request'

// ==================== 编程题目管理 ====================

// 分页查询题目
export function getProblemPage(params) {
  return request({
    url: '/v1/problems',
    method: 'get',
    params
  })
}

// 获取题目详情
export function getProblemDetail(id) {
  return request({
    url: `/v1/problems/${id}`,
    method: 'get'
  })
}

// 创建题目
export function createProblem(data) {
  return request({
    url: '/v1/problems',
    method: 'post',
    data
  })
}

// 更新题目
export function updateProblem(id, data) {
  return request({
    url: `/v1/problems/${id}`,
    method: 'put',
    data
  })
}

// 删除题目
export function deleteProblem(id) {
  return request({
    url: `/v1/problems/${id}`,
    method: 'delete'
  })
}

// 发布题目
export function publishProblem(id) {
  return request({
    url: `/v1/problems/${id}/publish`,
    method: 'post'
  })
}

// 下架题目
export function unpublishProblem(id) {
  return request({
    url: `/v1/problems/${id}/unpublish`,
    method: 'post'
  })
}

// 批量导入题目
export function importProblems(data) {
  return request({
    url: '/v1/problems/import',
    method: 'post',
    data
  })
}

// 导出题目
export function exportProblems(params) {
  return request({
    url: '/v1/problems/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// 获取题目统计
export function getProblemStatistics(id) {
  return request({
    url: `/v1/problems/${id}/statistics`,
    method: 'get'
  })
}

// 更新题目状态
export function updateProblemStatus(id, status) {
  return request({
    url: `/v1/problems/${id}/status`,
    method: 'put',
    data: { status }
  })
}

// ==================== 测试用例管理 ====================

// 获取测试用例列表
export function getTestCaseList(problemId) {
  return request({
    url: `/v1/test-cases/problem/${problemId}`,
    method: 'get'
  })
}

// 创建测试用例
export function createTestCase(data) {
  return request({
    url: '/v1/test-cases',
    method: 'post',
    data
  })
}

// 更新测试用例
export function updateTestCase(id, data) {
  return request({
    url: `/v1/test-cases/${id}`,
    method: 'put',
    data
  })
}

// 删除测试用例
export function deleteTestCase(id) {
  return request({
    url: `/v1/test-cases/${id}`,
    method: 'delete'
  })
}

// 批量创建测试用例
export function batchCreateTestCases(data) {
  return request({
    url: '/v1/test-cases/batch',
    method: 'post',
    data
  })
}

// ==================== 提交记录管理 ====================

// 分页查询提交记录
export function getSubmissionPage(params) {
  return request({
    url: '/v1/submissions',
    method: 'get',
    params
  })
}

// 获取提交详情
export function getSubmissionDetail(id) {
  return request({
    url: `/v1/submissions/${id}`,
    method: 'get'
  })
}

// 重新评测
export function rejudgeSubmission(id) {
  return request({
    url: `/v1/submissions/${id}/rejudge`,
    method: 'post'
  })
}

// 获取排行榜
export function getLeaderboard(params) {
  return request({
    url: '/v1/submissions/leaderboard',
    method: 'get',
    params
  })
}

// 获取用户提交统计
export function getUserSubmissionStats(userId) {
  return request({
    url: `/v1/submissions/user/${userId}/stats`,
    method: 'get'
  })
}

// 导出提交记录
export function exportSubmissions(params) {
  return request({
    url: '/v1/submissions/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// ==================== 代码执行管理 ====================

// 执行代码
export function executeCode(data) {
  return request({
    url: '/v1/code/execute',
    method: 'post',
    data
  })
}

// 提交代码
export function submitCode(data) {
  return request({
    url: '/v1/code/submit',
    method: 'post',
    data
  })
}

// 获取执行结果
export function getExecutionResult(executionId) {
  return request({
    url: `/v1/code/execution/${executionId}`,
    method: 'get'
  })
}

// ==================== 编程分类管理 ====================

// 获取分类列表
export function getProblemCategoryList() {
  return request({
    url: '/v1/problem-categories',
    method: 'get'
  })
}

// 获取分类树
export function getProblemCategoryTree() {
  return request({
    url: '/v1/problem-categories/tree',
    method: 'get'
  })
}

// 创建分类
export function createProblemCategory(data) {
  return request({
    url: '/v1/problem-categories',
    method: 'post',
    data
  })
}

// 更新分类
export function updateProblemCategory(id, data) {
  return request({
    url: `/v1/problem-categories/${id}`,
    method: 'put',
    data
  })
}

// 删除分类
export function deleteProblemCategory(id) {
  return request({
    url: `/v1/problem-categories/${id}`,
    method: 'delete'
  })
}

// ==================== 编程标签管理 ====================

// 获取标签列表
export function getProblemTagList() {
  return request({
    url: '/v1/problem-tags',
    method: 'get'
  })
}

// 创建标签
export function createProblemTag(data) {
  return request({
    url: '/v1/problem-tags',
    method: 'post',
    data
  })
}

// 更新标签
export function updateProblemTag(id, data) {
  return request({
    url: `/v1/problem-tags/${id}`,
    method: 'put',
    data
  })
}

// 删除标签
export function deleteProblemTag(id) {
  return request({
    url: `/v1/problem-tags/${id}`,
    method: 'delete'
  })
}
